<template>
  <div>
    <el-form inline :model="queryData" ref="queryData" class="query-form">

      <el-form-item label="合同单号:" prop="contractNo">
        <el-input v-model="queryData.contractNo" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('contractNo')"/>
      </el-form-item>
      <el-form-item label="园区名称:" prop="gardenName">
        <el-input v-model="queryData.gardenName" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('gardenName')"/>
      </el-form-item>

      <el-form-item label="企业名称:" prop="enterpriseName">
        <el-input v-model="queryData.enterpriseName" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('enterpriseName')"/>
      </el-form-item>

      <el-form-item label="房源名称:" prop="assessName">
        <el-input v-model="queryData.assessName" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('assessName')"/>
      </el-form-item>

      <el-form-item label="添加时间:" prop="createTime">
        <el-date-picker v-model="queryData.createTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" clearable @clear="formClear('createTime')">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="房源经纪人:" prop="housingAgentName">
        <el-input v-model="queryData.housingAgentName" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('housingAgentName')"/>
      </el-form-item>

      <el-form-item label="带看经纪人:" prop="lookAgentName">
        <el-input v-model="queryData.lookAgentName" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('lookAgentName')"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">查 询</el-button>
        <el-button @click="onReset">重 置</el-button>
        <el-button type="primary" @click="lookOverEvent(null)">新 增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableList" border style="width: 100%;">
      <el-table-column prop="contractNo" label="合同单号" align="center" width="150"/>
      <el-table-column prop="gardenName" label="园区名称" align="center" width="150"/>
      <el-table-column prop="assessName" label="房源名称" align="center"/>
      <el-table-column prop="enterpriseName" label="企业名称" align="center" width="130" show-overflow-tooltip/>
      <el-table-column prop="housingAgentName" label="房源经纪人名称" align="center" width="130" show-overflow-tooltip/>
      <el-table-column prop="housingAgentUsrId" label="房源经纪人UID" align="center" width="130"/>
      <el-table-column prop="lookAgentName" label="带看经纪人名称" align="center" width="130" show-overflow-tooltip/>
      <el-table-column prop="lookAgentUsrId" label="带看经纪人UID" align="center" width="130"/>
      <el-table-column prop="money" label="签约金额" align="center"/>
      <el-table-column prop="createTime" label="添加时间" align="center" width="200" show-overflow-tooltip/>
      <el-table-column prop="operator" label="添加人" align="center"/>
      <el-table-column label="操作" align="center" width="150" fixed="right">
        <template slot-scope="{row}">
          <el-button type="text" @click="lookOverEvent(row)">查 看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Paging v-model="queryData" @change="getRequest"></Paging>
    <el-drawer title="合同信息" :visible.sync="drawer" direction="rtl" :before-close="drawerClose" size="500px"
               destroy-on-close class="drawer-css">
      <ContractForm :entity="entity" v-if="drawer" @close="drawerClose" @refresh="getRequest"></ContractForm>
    </el-drawer>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    computed: {
      ...mapGetters(['confirm'])
    },
    components: {
      ContractForm: () => import('./ContractForm.vue')
    },
    name: 'contractList',
    data() {
      return {
        tableList: [],
        queryData: {
          assessName: null, // 房源名字
          contractNo: null, // 合同单号
          createTime: null, // 创建时间
          enterpriseName: null, // 企业名字
          gardenName: null, // 园区名字
          housingAgentName: null, // 房源经纪人名称
          lookAgentName: null, // 带看经纪人名称
          pageNum: 1,
          pageSize: 10,
          total: 0
        },
        entity: null,
        drawer: false
      }
    },
    beforeMount() {
      this.getRequest()
    },
    methods: {
      /**
       * 新增 or 查看按钮事件
       */
      lookOverEvent (row) {
        this.entity = row ? JSON.parse(JSON.stringify(row)) : null
        this.drawer = true
      },
      /**
       * 关闭抽屉
       */
      drawerClose () {
        this.drawer = false;
        this.entity = null
      },
      /**
       * 重置事件
       */
      onReset() {
        this.queryData.pageNum = 1
        this.queryData.province = null
        this.queryData.city = null
        this.queryData.county = null
        this.$refs['queryData'].resetFields()
        this.getRequest()
      },
      /**
       * 查询条件提交事件
       */
      onSubmit() {
        this.queryData.pageNum = 1
        this.getRequest()
      },
      /**
       * 列表请求事件
       */
      async getRequest() {
        const params = JSON.parse(JSON.stringify(this.queryData))
        const res = await this.$ajax.get('/wx/contract/backstage/list', { params })
        this.queryData.total = res.total
        this.tableList = res.rows
      },
      /**
       * form-input 置空事件
       */
      formClear(key) {
        this.queryData[key] = null
        this.onSubmit()
      }
    }
  }
</script>

<style scoped>
</style>
